function [response_pre,response_stim]=fret_ratio(data_ch1,data_ch2,params)

[im_width,im_height,number_of_frames]=size(data_ch1);

if number_of_frames~=params.nbr_repetitions*params.nbr_stimuli*params.frames_per_stim
    warndlg(['The data and parameters you have provieded do not match in total number of frames. ' ...
        'Aborting the execution of the program.'])
    return
end

%fret_ratio=data_ch1./data_ch2;

response_pre=zeros(im_width,im_height,params.nbr_stimuli);
response_stim=zeros(im_width,im_height,params.nbr_stimuli);

for ind=1:params.nbr_stimuli
    curr_pre_indices = [1+params.boundary:params.frames_pre] + (ind-1)*params.frames_per_stim;
    curr_stim_indices = [params.frames_pre+1+params.boundary:params.frames_pre+params.frames_stim] + (ind-1)*params.frames_per_stim;
    for knd=1:params.nbr_repetitions-1
        curr_pre_indices=[curr_pre_indices curr_pre_indices(1:params.frames_pre-params.boundary)+knd*params.nbr_stimuli*params.frames_per_stim];
        curr_stim_indices=[curr_stim_indices curr_stim_indices(1:params.frames_pre-params.boundary)+knd*params.nbr_stimuli*params.frames_per_stim];
    end
    response_pre(:,:,ind)=mean(data_ch1(:,:,curr_pre_indices)./data_ch2(:,:,curr_pre_indices),3);
    response_stim(:,:,ind)=mean(data_ch1(:,:,curr_stim_indices)./data_ch2(:,:,curr_stim_indices),3);
end

response_pre(isinf(response_pre)) = 0;
response_pre(isnan(response_pre)) = 0;

response_stim(isinf(response_stim)) = 0;
response_stim(isnan(response_stim)) = 0;

sp_filter=fspecial('gaussian', 20, 3.84);

for ind=1:params.nbr_stimuli
    figure(ind);
    clf;
    temp=Filter2Modified(sp_filter,response_stim(:,:,ind))./Filter2Modified(sp_filter,sum(response_pre(:,:,:),3));
    temp_std=std(temp(:));
    temp_median=median(temp(:));
    
    imagesc(temp,[temp_median-2*temp_std,temp_median+2*temp_std]);
end
    